<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use app\common\model\AdminUser;
use app\common\model\Article;
use app\common\model\Category;

class Index extends Controller{
	function __construct(){
		parent::__construct();
		// 强制返回系统入口
		$request = Request::instance();
		$action = $request->controller().'/'.$request->action();
		if($action != 'Index/index' && !$request->isPjax() && !$request->isPost()){
			// cookie('to_url',$request->url());
			// echo '<script>window.location.href=\'http://blog.0715ym.com/\';'.'</script>';
		}
	}

  public function cs(){
    
    return $this->fetch();
  }

  public function index(){
  	$cate = new Category;
  	$article = new Article;
  	$cate_list = $cate->get_list();
  	$this->assign('cate',$cate_list);
  	$this->assign('to_url',input('cookie.to_url'));
  	cookie('to_url',null);
    return $this->fetch();
  }

  public function cate_list($id){
  	$article = new Article;
    if($id == 16){
      $data_list = $article->find_cate_list($id);
      $this->assign('list',$data_list);
      return $this->fetch('index/about');
    }
    if($id == 19 | $id == 18){
      $data_list = $article->find_cate_list($id);
      $this->assign('list',$data_list);
      return $this->fetch();
    }  	
  }

  public function get_cate(){
    $cate = new Category;
    $article = new Article;
    $cate_list = $cate->get_list();
    return json($cate_list);
  }

  public function get_cate_list($id){
    $article = new Article;
    $data_list = $article->find_cate_list($id);
    if(sizeof($data_list)){
      return json($data_list);
    }else{
      return json(null);
    }
    
  }

  public function get_article($id){
    $article = new Article;
    $data = $article->find($id)->toArray();
    return json($data);
  }
}
